import {request} from 'network/request'

/**
 * 登录
 * @param {Object} data 
 */
export function login(data){
    return request({
        url: '/login',
        method: 'post',
        data: data
    })
}



/**
 * 注销
 */
export function logout(){
    return request({
        url: 'logout',
        method: 'get',
        headers: {
            "Authorization": localStorage.getItem("token")
        }
    })
}



/**
 * 博客列表
 * @param {number} currentPage 
 */
export function blogs(currentPage, pageSize){
    return request({
        url: '/blogs',
        method: 'get',
        params: {
            currentPage,
            pageSize
        }
    })
}


/**
 * 根据id获取博客详情
 * @param {number} id 
 */
export function getBlogById(id){
    return request({
        url: 'blog/'+id,
        method: 'get'
    })
}


/**
 * 提交博客
 * @param {Object} data 
 */
export function blogEdit(data){
    return request({
        url: 'blog/edit',
        method: 'post',
        data: data,
        headers: {
            "Authorization": localStorage.getItem("token")
        }
    })
}





/**
 * 评论列表
 * @param {*} config 
 */
export function getCommentInfo(config){
    return request({
        url: 'comment/list',
        method: 'get',
        params: config
    })
}


/**
 * 游客身份验证
 * @param {*} config 
 */
export function touristSave(config){
    return request({
        url: '/tourist/save',
        method: 'post',
        data: config
    })
}


/**
 * 发表评论
 * @param {*} config 
 */
export function commentAdd(config){
    return request({
        url: "/comment/add",
        method: 'post',
        data: config
    })
}

/**
 * 获取分类数据
 */
export function classList(){
    return request({
        url: "/class/list",
        method: 'get',
    })
}

/**
 * 根据分类获取博客列表
 * @param {*} classId 
 */
export function getBlogsByClass(classId){
    return request({
        url: '/blog/class/'+classId,
        method: 'get'
    })
}

/**
 * 获取笔记
 * @param {*} id 
 */
export function getNoteById(id){
    return request({
        url: '/note/'+id,
        method: 'get'
    })
}

/**
 * 后台获取博客列表
 * @param {*} config 
 */
export function getBlogList(config){
    return request({
        url: '/blog/backList',
        headers: {
            "Authorization": localStorage.getItem("token")
        },
        method: 'get',
        params: config
    })
}

/**
 * 根据ID删除博客
 * @param {*} id 
 */
export function deleteBlogById(id){
    return request({
        url: "/blog/delete",
        headers: {
            "Authorization": localStorage.getItem("token")
        },
        method: 'post',
        data: {
            id: id
        }
    })
}

/**
 * 获取class列表
 */
export function getClass(){
    return request({
        url: "/class/nlist",
        method: "get"
    })
}

/**
 * 博客修改和新增
 * @param {*} config 
 */
export function blogUpdate(config){
    return request({
        url: '/blog/edit',
        headers: {
            "Authorization": localStorage.getItem("token")
        },
        method: 'post',
        data: config
    })
}